package com;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.Field;
import org.mybatis.generator.api.dom.java.Method;
import org.mybatis.generator.api.dom.java.Parameter;
import org.mybatis.generator.api.dom.xml.XmlElement;
import org.mybatis.generator.internal.DefaultCommentGenerator;

/**
 *@auth thj
 *@time 2018-05-11 15:23:42
 */
public class MyCommentGenerator extends DefaultCommentGenerator {

	private boolean suppressAllComments;

	/**
	 * 字段属性注释
	 */
	@Override
	public void addFieldComment(Field field, IntrospectedTable introspectedTable,
								IntrospectedColumn introspectedColumn) {
		if (suppressAllComments) {
			return;
		}
		StringBuilder sb = new StringBuilder();
		field.addJavaDocLine("/**");
		sb.append(" * ");
		sb.append(introspectedColumn.getRemarks());
		field.addJavaDocLine(sb.toString());
		field.addJavaDocLine(" */");
	}

	/**
	 * get方法注释
	 */
	@Override
	public void addGetterComment(Method method, IntrospectedTable introspectedTable,
								 IntrospectedColumn introspectedColumn) {
		if (suppressAllComments) {
			return;
		}
		//method.addJavaDocLine("/**");
		StringBuilder sb = new StringBuilder();
		sb.append(" * 获取 ");
		sb.append(introspectedColumn.getRemarks());
		//method.addJavaDocLine(sb.toString());

		sb.setLength(0);
		sb.append(" * @return ");
		sb.append(introspectedColumn.getActualColumnName());
		//method.addJavaDocLine(sb.toString());
		//method.addJavaDocLine(" */");
	}

	/**
	 * set注释
	 */
	@Override
	public void addSetterComment(Method method, IntrospectedTable introspectedTable,
								 IntrospectedColumn introspectedColumn) {
		if (suppressAllComments) {
			return;
		}
		//method.addJavaDocLine("/**");
		StringBuilder sb = new StringBuilder();
		sb.append(" * 设置 ");
		sb.append(introspectedColumn.getRemarks());
		//method.addJavaDocLine(sb.toString());

		Parameter parm = method.getParameters().get(0);
		sb.setLength(0);
		sb.append(" * @param ");
		sb.append(parm.getName());
		//method.addJavaDocLine(sb.toString());
		//method.addJavaDocLine(" */");
	}

	// 添加xml文件的注释("完全反人类 没用")
	@Override
	public void addComment(XmlElement xmlElement) {
		if (suppressAllComments) {
			return;
		}
	}
}